package com.endava.spring.dao_impl;

import java.util.List;

import com.endava.spring.beans.Account;
import com.endava.spring.dao_interface.AccountDao;
import com.endava.spring.dao_interface.DataSourceDao;

/**
 * Implements the methods of interface <code>Account</code>.
 * 
 * @author acojocar
 * @since 30.07.2013
 * @version 1.0
 * 
 */
public class AccountJDBCTemplate extends DataSourceDao implements AccountDao {

	@Override
	public void create(Integer accountID, String accountType, Integer amount) {
		jdbcTemplate.update(INSERT_QUERY, new Object[] { accountID,
				accountType, amount });
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Account> getAllAccounts() {
		List<Account> accounts = jdbcTemplate.query(SELECT_ALL_QUERY,
				new AccountMapper());
		return accounts;
	}

	@Override
	public void delete(Integer accountID) {
		jdbcTemplate.update(DELETE_QUERY, new Integer[] { accountID });
	}

	@Override
	public void update(Integer accountID, Integer amount) {
		jdbcTemplate.update(UPDATE_QUERY, new Object[] { amount,
				new Integer(accountID) });
	}

}
